package com.mresources.common.auth;

import lombok.*;

import java.util.List;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Oauth2Config {
    private String clientID;
    private String clientSecret;
    private List<String> scopes;
    private String redirectURL;
    private EndPoint endPoint;
    private String authServerURL;
    private String state;

    public String generateOauth2Url() {
        return authServerURL + endPoint.getAuthURL() + "?" +
                "client_id=" + clientID + "&" +
                "redirect_uri=" + redirectURL + "&" +
                "response_type=" + "code" + "&" +
                "scopes=" + String.join(",", scopes) + "&" +
                "state=" + state;
    }

    public String fetchOauth2TokenUrl(String code, String state) {
        return authServerURL + endPoint.getTokenURL() + "?" +
                "client_id=" + clientID + "&" +
                "grant_type=" + "authorization_code" + "&" +
                "redirect_uri=" + redirectURL + "&" +
                "scopes=" + String.join(",", scopes) + "&" +
                "code=" + code + "&" +
                "state=" + state;
    }

    public String refreshOauth2TokenUrl() {
        return authServerURL + endPoint.getAuthURL() + "?" +
                "client_id=" + clientID + "&" +
                "redirect_uri=" + redirectURL + "&" +
                "response_type=" + "code" + "&" +
                "scopes=" + String.join(",", scopes) + "&" +
                "state=" + state;
    }
}


